import VueRouter from "vue-router";

const routes = [
    {
        path:'/',
        name:'IndexPageR',
        component:()=>import('../components/IndexPageR.vue'),
    },
    {
        path: '/LoginPage',
        name: 'LoginPage',
        component:()=>import('../components/LoginPage.vue')
    },
    {
        path:'/RegisterPage',
        name:'RegisterPage',
        component:()=>import('../components/regular/RegisterPage.vue')
    },
    {
        path:'/AdoptionPage',
        name:'AdoptionPage',
        component:()=>import('../components/regular/AdoptionPage.vue')
    },
    {
        path:'/PetSearch',
        name:'PetSearch',
        component:()=>import('../components/regular/PetSearch.vue')
    },
    {
        path:'/MyAccount',
        name:'MyAccount',
        component:()=>import('../components/regular/MyAccount.vue')
    },
    {
        path:'/IndexPage',
        name:'IndexPage',
        component:()=>import('../components/IndexPage.vue'),
        children:[
            {
                path:'/HomePage',
                name:'HomePage',
                meta:{
                    title:'首页'
                },
                component:()=>import('../components/HomePage.vue')
            },
        ]
    },
]

const router = new VueRouter({
    mode:'history',
    routes,
    scrollBehavior(to) {
        if (to.hash) {
            return {
                selector: to.hash,
                offset: { y: 75 }, // 根据实际导航栏高度调整
                behavior: 'smooth'
            }
        }
        return { x: 0, y: 0 }
    }
})
export function resetRouter() {
    router.matcher = new VueRouter({
        mode:'history',
        routes: []
    }).matcher
}
const VueRouterPush = VueRouter.prototype.push//路由报错处理
VueRouter.prototype.push = function push (to){
    return VueRouterPush.call(this, to).catch(err => err)
}
export default router;